﻿Option Explicit On
Option Strict On

Imports LogginsLogDSTableAdapters

Partial Class private_RegEntity
    Inherits System.Web.UI.Page
    Dim u As MembershipUser
    Dim personId As Int32
    Dim index As Int32

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim getpersonid As New GetPersonIdFromUserId()
        u = Membership.GetUser(User.Identity.Name)
        Try
            personId = getpersonid.GetPersonId(CType(u.ProviderUserKey, Guid))
            Dim entityidTA As New LogginsLogDSTableAdapters.usp_GetEntityListFull_ByPersonIdTableAdapter()
            Dim entityidDT As LogginsLogDS.usp_GetEntityListFull_ByPersonIdDataTable
            entityidDT = entityidTA.GetData(personId)
            For Each entityidRow As LogginsLogDS.usp_GetEntityListFull_ByPersonIdRow In entityidDT
                index = entityidRow.ID
            Next
            'Dim dateenteredtextbox As TextBox = CType(Me.FormView1.FindControl("DateCreatedTextBox"), TextBox)
            'dateenteredtextbox.Text = CStr(DateTime.Now)
        Catch ex As Exception
            Throw ex
        End Try
        'btnInsert.Visible = False
        'btnUpdate.Visible = False
    End Sub

    Protected Sub ObjectDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        e.InputParameters("EntityID") = index
    End Sub

    'Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand


    '    If e.CommandName = "DeleteRow" Then
    '        Dim delnumber As Integer = Convert.ToInt32(e.CommandArgument)
    '        Try
    '            Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
    '            entityTA.Delete(delnumber)
    '        Catch ex As Exception
    '            Throw ex
    '        End Try

    '        Try
    '            Dim personentitypeexpTA As New LogginsLogDSTableAdapters.SPTableAdapter()
    '            personentitypeexpTA.usp_PersonEntity_ExpDelete_ByPersonEntityId(personId, delnumber)
    '        Catch ex As Exception
    '            Throw ex
    '        End Try
    '        GridView1.DataBind()


    '    ElseIf e.CommandName = "UpdateRow" Then
    '        Session("gridarg") = Convert.ToInt32(e.CommandArgument)
    '        btnInsert.Visible = False
    '        btnUpdate.Visible = True
    '        Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
    '        Dim entityDT As LogginsLogDS.usp_EntityDataTable
    '        entityDT = entityTA.GetDataBy(Convert.ToInt32(e.CommandArgument))
    '        For Each entityRow As LogginsLogDS.usp_EntityRow In entityDT
    '            txtName.Text = entityRow.Name
    '            txtCompanyRegNo.Text = entityRow.CompanyRegNo
    '            txtVATRegNo.Text = entityRow.VATRegNo
    '        Next
    '        DisabledByAdminModalPopupExtender1.Show()
    '    End If
    'End Sub


    'Protected Sub LinkButton3_Click(sender As Object, e As System.EventArgs) Handles LinkButton3.Click
    '    btnInsert.Visible = True
    '    btnUpdate.Visible = False
    '    txtName.Text = String.Empty
    '    txtVATRegNo.Text = String.Empty
    '    txtCompanyRegNo.Text = String.Empty
    '    DisabledByAdminModalPopupExtender1.Show()
    'End Sub

    'Protected Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click
    '    Dim gridarg As Integer = CInt(Session("gridarg"))
    '    Try
    '        If txtName.Text = String.Empty Then
    '            lblName.Visible = True
    '            Return

    '        ElseIf txtVATRegNo.Text = String.Empty Then
    '            lblVATRegNo.Visible = True
    '            Return

    '        ElseIf txtCompanyRegNo.Text = String.Empty Then
    '            lblCompanyRegNo.Visible = True
    '            Return

    '        Else
    '            Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
    '            entityTA.Update(txtName.Text, txtCompanyRegNo.Text, Date.Now, txtVATRegNo.Text, 0, True, gridarg, gridarg)
    '            DisabledByAdminModalPopupExtender1.Hide()

    '        End If
    '        GridView1.DataBind()
    '    Catch ex As Exception
    '        Throw ex
    '    End Try

    'End Sub

    'Protected Sub btnInsert_Click(sender As Object, e As System.EventArgs) Handles btnInsert.Click

    '    Dim justinsertedentity As Integer?
    '    Try
    '        If txtName.Text = String.Empty Then
    '            lblName.Visible = True
    '            Return
    '        ElseIf txtVATRegNo.Text = String.Empty Then
    '            lblVATRegNo.Visible = True
    '            Return
    '        ElseIf txtCompanyRegNo.Text = String.Empty Then
    '            lblCompanyRegNo.Visible = True
    '            Return
    '        Else
    '            Dim entityTA As New LogginsLogDSTableAdapters.usp_EntityTableAdapter()
    '            entityTA.Insert(txtName.Text, txtCompanyRegNo.Text, Date.Now, txtVATRegNo.Text, 0, True, justinsertedentity)

    '        End If
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    '    Try
    '        Dim personentitypeexpTA As New LogginsLogDSTableAdapters.usp_PersonEntity_ExpTableAdapter()
    '        personentitypeexpTA.Insert(personId, justinsertedentity, True)
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    '    GridView1.DataBind()
    '    DisabledByAdminModalPopupExtender1.Hide()
    'End Sub

    Protected Sub ObjectDataSource1_Updated(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Updated
        Try
            u = Membership.GetUser(User.Identity.Name)
            Dim getuseracccheckdataTA As New usp_UserCheckTableAdapter()
            Dim getuseracccheckdataDT As LogginsLogDS.usp_UserCheckDataTable
            getuseracccheckdataDT = getuseracccheckdataTA.GetData(CType(u.ProviderUserKey, Global.System.Guid?))

            For Each getuseracccheckdataRow As LogginsLogDS.usp_UserCheckRow In getuseracccheckdataDT
                getuseracccheckdataTA.Update(getuseracccheckdataRow.UserId, getuseracccheckdataRow.AccountInCredit, _
                                             getuseracccheckdataRow.ApprovalRequired, _
                                             getuseracccheckdataRow.RegistrationComplete, _
                                             getuseracccheckdataRow.EmailConfirmed, _
                                             getuseracccheckdataRow.AwaitingApproval, _
                                             getuseracccheckdataRow.AccountActive, _
                                             getuseracccheckdataRow.UserPlanChosen, _
                                             getuseracccheckdataRow.Active, _
                                             getuseracccheckdataRow.UserRoleSet, _
                                             CType(1, Boolean?), _
                                             getuseracccheckdataRow.Id, _
                                             getuseracccheckdataRow.AcceptedTrialPlan)

            Next
        Catch ex As Exception
            Throw ex
        End Try

        Response.Redirect("~/private/default.aspx")
    End Sub
End Class
